import pickle

data = '张三'


def pickle_wr():
    with open('some.pickle', 'wb') as f:  #
        pickle.dump(data, f)

    with open('some.pickle', 'rb') as f:
        print(pickle.load(f))

    s = pickle.dumps(data)  # 将一个对象转储为一个字符串
    s1 = pickle.loads(s)
    print(s1)


f = open('somedata', 'wb')
pickle.dump([1, 2, 3, 4], f)
pickle.dump('hello', f)
pickle.dump({'Apple', 'Pear', 'Banana'}, f)
f.close()

f1 = open('somedata', 'rb')
pickle.load(f1)  # [1, 2, 3, 4]
pickle.load(f1)  # 'hello'
f1.close()

# dump和load主要针对是文件写，读
# dumps 和loads主要针对的就是对象的读写
